package sketch.ast;

import java.util.Collection;
import java.util.List;

import org.eclipse.jdt.core.dom.Block;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;

import sketch.main.SketchTestOptions;
import sketch.util.SketchUtil;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class ASTFindVariableDeclarationTest extends TestCase {
	
	public static Test suite() {
		return new TestSuite(ASTFindVariableDeclarationTest.class);
	}
	
	public void testFindVariableDeclarationStatementNonRecursively() {
		String filePath = "./testfiles/sketch/ast/TreeMapSketchExecutionForTest.java";
		CompilationUnit unit = ASTUtils.astRoot(filePath);
		List<MethodDeclaration> methods = ASTUtils.getMethodsWithAnnotation(unit, "TestSketch");
		for(MethodDeclaration method : methods) {
			Block block = method.getBody();
			Collection<VariableDeclarationStatement> varList = ASTUtils.getVariableDeclarations(block);
			if(SketchTestOptions.verbose) {
				SketchUtil.stdln("The value declaration statement size: " + varList.size());
			}
			assertTrue(varList.isEmpty());
		}
		SketchUtil.stdln("\n\n");
	}
	
	public void testFindVariableDeclarationStatementRecursively() {
		String filePath = "./testfiles/sketch/ast/TreeMapSketchExecutionForTest.java";
		CompilationUnit unit = ASTUtils.astRoot(filePath);
		List<MethodDeclaration> methods = ASTUtils.getMethodsWithAnnotation(unit, "TestSketch");
		for(MethodDeclaration method : methods) {
			Block block = method.getBody();
			Collection<VariableDeclarationStatement> varList = ASTUtils.getVariableDeclarationsRecursively(block);
			SketchUtil.stdln("The value declaration statement size in a non-recursively manner: " + varList.size());
			assertFalse(varList.isEmpty());;
			for(VariableDeclarationStatement statement : varList) {
				SketchUtil.stdln("decl statement : " + statement);
			}
		}
		SketchUtil.stdln("\n\n");
	}
}
